﻿using System;
using System.Collections.Generic;
using System.Text;
using WorkFlowCore.IRepositories;
using Microsoft.Extensions.DependencyInjection;

namespace WorkFlowCore.Framework.Repositories
{
    public class UnitOfWorkManager : IUnitOfWorkManager
    {
        private readonly IServiceProvider serviceProvider;

        public UnitOfWorkManager(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
        }

        public IUnitOfWork Begin()
        {
            var unitOfWork = serviceProvider.GetService<IUnitOfWork>();
            if(unitOfWork is UnitOfWork)
            {
                ((UnitOfWork)unitOfWork).Begin();
            }
            return unitOfWork;
        }
    }
}
